﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Xml;
using Youz.Common.Helper;
using Youz.CreditRepay.BLL;
using Youz.CreditRepay.Entity;

namespace Youz.CreditRepay.Manage.PayEase.Handlers
{
    /// <summary>
    /// PayEaseHandler 的摘要说明
    /// </summary>
    public class PayEaseHandler : IHttpHandler
    {
        Member_WithdrawBLL bllWithdraw = new Member_WithdrawBLL();

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string _type = WebHelper.Get("type");
            string result = string.Empty;
            
            switch (_type)
            {
                case "GetBalance":
                    result = GetBalance();
                    break;
                case "AddPayment":
                    result = AddPayment();
                    break;
                case "GetStatus":
                    result = GetStatus();
                    break;
            }

            context.Response.Write(result);
            context.Response.End();
        }

        private string GetStatus()
        {
            var id = WebHelper.Post("ID");
            if (!string.IsNullOrEmpty(id))
            {
                return Core.AjaxResult(true, bllWithdraw.GetPayEaseStatus(id));
            }

            return Core.AjaxResult(false);
        }

        private string GetBalance()
        {
            return bllWithdraw.GetPayEaseBalance();
        }

        private string AddPayment()
        {
            return bllWithdraw.SubmitPayEasePayment();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}